﻿document.oncontextmenu = function () { return false; };

$(function () {


    $('[data-toggle="tooltip"]').tooltip();
    $(".mheader").mousemove(function (e) {
        var el = e.srcElement || e.target;
        if ($(el).attr("move") != "false") {
            SysControl.MoveForm();
        }
    });
    $("#btnViewLog").click(function () {

        SysControl.ViewLog();
    });
    $("#btnRestart").click(function () {
        LayerConfirm('确定重新启动？', function () {
            SysControl.Restart();
        });


    });
    $("#btnQuitSystem").click(function () {
        LayerConfirm('确定退出程序？', function () {
            SysControl.QuitSystem();
        });


    });
    $("#btnHideForm").click(function () {
        SysControl.HideForm();
    });

    $("#reportPath").click(function () {

        var selectPath = SysControl.SelectPath();
        if (selectPath != "") {
            $("#reportPath").val(selectPath);
        }

    });

    $("#saveConfig").click(function () {

        if ($("#shareIp").val() == "") {
            LayerErrorMsg("服务器IP地址不能为空");
            $("#shareIp").focus();
            return;
        }
        if ($("#sharePath").val() == "") {
            LayerErrorMsg("共享文件夹路径不能为空");
            $("#sharePath").focus();
            return;
        }
        if ($("#reportPath").val() == "") {
            LayerErrorMsg("本地报表监测路径不能为空");
            $("#reportPath").focus();
            return;
        }
        var saveModel =
            {
                "ShareIp": $("#shareIp").val(),
                "SharePath": $("#sharePath").val(),
                "ShareUserName": $("#shareUserName").val(),
                "ShareUserPwd": $("#shareUserPwd").val(),
                "ReportPath": $("#reportPath").val(),
                "IsAddDatePath": $("#IsAddDatePath").val(),
            };
        var result = JSON.parse(SysControl.SaveConfig(JSON.stringify(saveModel)));
        if (result.status == 0) {
            LayerSuccessMsg(result.message, function () {
                ConfigModel = saveModel;
                layer.confirm(
                    "应用配置保存成功！<br/>立即重新启动程序以应用新配置？",
                    { btn: ['立即重新启动', '稍后重新启动'], icon: 3, title: '提示', closeBtn: 0, move: false },
                    function () {
                        SysControl.Restart();
                    },
                    function () {

                    }
                );
            })
        }
        else {
            LayerErrorMsg(result.message);
        }
    });
})
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
function setFormValue(configJson) {


    $("#shareIp").val(configJson.ShareIp);
    $("#sharePath").val(configJson.SharePath);
    $("#shareUserName").val(configJson.ShareUserName);
    $("#shareUserPwd").val(configJson.ShareUserPwd);
    $("#reportPath").val(configJson.ReportPath);
    $("input[name='isAddDatePath'][value=" + configJson.IsAddDatePath + "]").attr('checked', 'true');
}

function setWrongStatus(msg) {
    $(".run-normal").hide();
    $(".run-wrong span").text(msg);
    $(".run-wrong").show();
}
function setStatus(msg) {
    $(".run-wrong").hide();
    $(".run-normal span").text(msg);
    $(".run-normal").show();
}

function slideToSetting() {
    swiper.slideTo(1);
}

Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                 //月份 
        "d+": this.getDate(),                    //日 
        "h+": this.getHours(),                   //小时 
        "m+": this.getMinutes(),                 //分 
        "s+": this.getSeconds(),                 //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds()             //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}

var keyBordSetting = {

    display: {
        'bksp': '\u2190',
        'accept': 'return',
        'normal': 'ABC',
        'shift': '\u21d1',
        'meta1': '.?123',
        'meta2': '#+='
    },

    layout: 'custom',

    customLayout: {

        'normal': [
            'q w e r t y u i o {bksp}',
            'a s d f g h j k l p',
            '{s} z x c v b n m . 中',
            '{meta1} {space} {accept}'
        ],
        'shift': [
            'Q W E R T Y U I O {bksp}',
            'A S D F G H J K L P',
            '{s} Z X C V B N M ! ?',
            '{meta1} {space} {accept}'
        ],
        'meta1': [
            '1 2 3 4 5 6 7 8 9 {bksp}',
            '0 - / : ; ( ) \u20ac & @',
            '{meta2} . , ? ! \' " {meta2} {enter}',
            '{normal} {space} {accept}'
        ],
        'meta2': [
            '[ ] { } # % ^ * + = {bksp}',
            '_ \\ | ~ < > $ \u00a3 \u00a5 {enter}',
            '{meta1} . , ? ! \' " {meta1}',
            '{normal} {space} {normal} {accept}'
        ]

    },
    userClosed: true,
    visible: function () {

        SimpleInputMethod.init('.numkeyboard');
    }

}


function HeadAnimation(element, animation,hValue) {
    element = $(element);
    element.addClass(animation);
    //动画完成之前移除class
    window.setTimeout(function () {
        element.css("height", hValue);
        element.css("line-height", hValue);
        element.removeClass(animation);
    }, 450);
}

function AjaxGet(loadingTxt, action, data, fun, error = null) {
    var loadingIndex = 0;
    if (loadingTxt != "") {
        loadingIndex = top.layer.msg(loadingTxt, {
            time: 0, icon: 16, shade: 0.01
        });
    }
    $.ajax({
        url: sessionStorage.CurrentHttpAddress + "/" + action,
        type: "get",
        data: data,
        context: document.body,
        success: function (res) {
            if (loadingIndex != 0) {
                top.layer.close(loadingIndex);
            }
            fun(res);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            if (error == null) {
                alert(errorThrown);
            }
            else {
                error(errorThrown);
            }
            top.layer.close(loadingIndex);
        }
    });
}

function getSampleStatusStr(status)
{
    var result = '';
    switch (status) {
        case 0:
            result = "无异常现象";
            break
        case 1:
            result = "爆炸";
            break
        case 2:
            result = "燃烧";
            break
        case 3:
            result = "明显变色";
            break;

        default:
    }
    return result;

}